//	ID : pallab81
// 	PROG : 10898
// 	LANG : C++
// 	2011-09-08-14.31.53 Thursday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define fo(i,ed) foR( i , 0 , ed )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ) {
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ) {
        ;
    }
}
int R,C,Q;
char grid[101][101];

inline void Read() {
    CI(R);
    CI(C);
    CI(Q);
    fo(i,R) {
        fo(j,C) {
            cin>>grid[i][j];
        }
    }
}
inline bool Nice(int upR, int doR, int leC, int riC) {
    return ( upR>=0 && doR<R && leC>=0 && riC<C );
}
inline void doit(int r, int c) {
    char ch=grid[r][c];
    //cout<<r<<" "<<c<<" go : \n";
    int mx=0;
    for(int i=0,flag=1 ;  flag!=0 ; ++i) {
        int upR = r-i;
        int doR = r+i;
        int leC = c-i;
        int riC = c+i;

        if( Nice(upR,doR,leC,riC)==false ) {
            flag=0;
            goto L;
        } else {

            foE(ri,upR,doR) {
                foE(ci,leC,riC) {
                    if( grid[ri][ci]!=ch ) {
                        flag=0;
                        goto L;
                    }
                }
            }
            //cout<<upR<<" "<<leC<<" "<<doR<<" "<<riC<<"\n";wait(.3);
            mx = (doR-upR)+1;
        }

    }
L:
   // printf("RESULT %d %d ",r,c);
    printf("%d\n",mx);
}
inline void Proc() {
    int r,c;
    printf("%d %d %d\n",R,C,Q);
    fo(i,Q) {
        CI(r);
        CI(c);
        doit(r,c);
    }
}
int main() {
//#ifndef ONLINE_JUDGE
//    freopen("in.txt","rt",stdin);
//#endif

    int cases=1;
    for( CI(cases) ; cases ; --cases ) {
        Read();
        Proc();
    }

    return 0;
}
